home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 2004 #9
/
Amiga Plus CD - 2004 - No. 09.iso
/
amigaplus
/
tools
/
dev_libs
/
feelin040718
/
demos
/
class2.c
< prev
next >
Wrap
C/C++ Source or Header
|
2004-08-03
|
5KB
|
210 lines
;/*
F_Create.rexx EXE Class2 Feelin:Sources/_ASM/Rnd.o
QUIT
_________________________________________________________________________
Class2 Demo © 2000-2003 by Olivier LAVIALE <HaploLaMain@aol.com>
This example illustrate how to writte a custom class using a methods
table instead of a dispatcher. This class doesn't use Dynamic IDs.
*/
#include <stdlib.h>
#include <libraries/feelin.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/graphics.h>
#include <proto/feelin.h>
struct FeelinBase *FeelinBase;
/* Here is the beginning of our simple new class... */
#define FM_Strobo FCCM_BASE
struct LocalObjectData
{
FAreaData *AreaData;
struct FeelinSignalHandler SignalHandler;
};
/// mNew
F_METHOD(ULONG,mNew)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
LOD -> AreaData = (FAreaData *) F_Get(Obj,FA_AreaData);
LOD -> SignalHandler.Object = Obj;
LOD -> SignalHandler.Method = FM_Strobo;
LOD -> SignalHandler.Flags = FF_SignalHandler_Timer;
LOD -> SignalHandler.fsh_Secs = 0;
LOD -> SignalHandler.fsh_Micros = 30000;
return F_SUPERDO();
}
//+
/// mShow
F_METHOD(LONG,mShow)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
if (F_SUPERDO())
{
F_Do(_app,FM_Application_AddSignalHandler,&LOD -> SignalHandler);
return TRUE;
}
return FALSE;
}
//+
/// mHide
F_METHOD(void,mHide)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
if (FF_Area_CanShow & _flags)
{
F_Do(_app,FM_Application_RemSignalHandler,&LOD -> SignalHandler);
}
F_SUPERDO();
}
//+
/// mAskMinMax
/*
AskMinMax method will be called before the window is opened and before
layout takes place. We need to tell Feelin the minimum and maximum size of
our object. Note that we indeed need to *add* these values, not just set
them !
*/
F_METHOD(ULONG,mAskMinMax)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
_minw += 30;
_minh += 30;
/*
Now call our superclass. FC_Area will handle everything, taking care of
FA_FixedXxx, FA_MinXxx and FA_MaxXxx.
*/
return F_SUPERDO();
}
//+
/// mDraw
/*
Draw method is called whenever Feelin feels (obviously ;-)) we should
render our object. This usually happens after layout is finished. Note: You
may only render within the rectangle _mx(Obj), _my(Obj), _mx2(Obj),
_my2(Obj).
*/
F_METHOD(void,mDraw)
{
struct LocalObjectData *LOD = F_LOD(Class,Obj);
struct RastPort *rp = _rp;
/*
let our superclass draw itself first, Area class would e.g. draw the frame
and clear the whole region. What it does exactly depends on flags.
*/
F_SUPERDO();
_APen(rand() % (1 << rp -> BitMap -> Depth));
_Boxf(_mx,_my,_mx2,_my2);
}
//+
///mStrobo
F_METHOD(LONG,mStrobo)
{
F_Draw(Obj,FF_Draw_Update);
return TRUE; // If we return FALSE the timer event won't be requested again
}
//+
///Main
void main()
{
APTR app,win;
struct FeelinClass *cc;
/*
Methods handled by the class.
*/
static struct FeelinMethodEntry Handlers[] =
{
(FMethod) mNew, NULL, FM_New,
(FMethod) mShow, NULL, FM_Show,
(FMethod) mHide, NULL, FM_Hide,
(FMethod) mAskMinMax, NULL, FM_AskMinMax,
(FMethod) mDraw, NULL, FM_Draw,
(FMethod) mStrobo, NULL, FM_Strobo,
NULL
};
if (FeelinBase = (APTR) OpenLibrary("feelin.library",FV_VERSION))
{
/*
Create the new custom class with a call to F_CreateClassA().
This function returns a struct FeelinClass. You must use cc -> Name to
create instance of your custom class. This Name is unique and made by
F_CreateClassA().
*/
if (cc = F_CreateClass(FA_Class_Super, FC_Area,
FA_Class_LODSize, sizeof (struct LocalObjectData),
FA_Class_MethodsTable, Handlers,
TAG_DONE))
{
app = AppObject,
FA_Application_Title, "Class2",
FA_Application_Version, "$VER: Class2 1.2 (2004/03/13)",
FA_Application_Copyright, "© 2000-2003 Olivier LAVIALE",
FA_Application_Author, "Olivier LAVIALE <HaploLaMain@aol.com>",
FA_Application_Description, "Tutorial on Client.AddSignalHandler()",
FA_Application_Base, "CLASS2",
Child, win = WindowObject,
FA_ID, "MAIN",
FA_Window_Title, "Crazy colors using Client.AddSignalHandler()",
FA_Window_Open, TRUE,
Child, VGroup, FA_Group_Rows, 2,
Child, F_NewObj(cc -> Name,GaugeFrame, DontChain, TAG_DONE),
Child, F_NewObj(cc -> Name,GaugeFrame, DontChain, TAG_DONE),
Child, F_NewObj(cc -> Name,GaugeFrame, DontChain, TAG_DONE),
Child, F_NewObj(cc -> Name,GaugeFrame, DontChain, TAG_DONE),
End,
End,
End;
if (app)
{
F_Do(win,FM_Notify,FA_Window_CloseRequest,TRUE, app,FM_Application_Shutdown,0);
F_Do(app,FM_Application_Run);
F_DisposeObj(app);
}
F_DeleteClass(cc);
}
else
{
Printf("Unable to create custom class.\n");
}
CloseLibrary(FeelinBase);
}
else
{
Printf("Failed to open feelin.library.\n");
}
}
//+